package com.team.util;


import com.team.constant.CommonConstant;

/**
 * @author Administrator
 * @version 1.0
 * @date 2021/12/20 14:27
 * @Description:统一返回结果工具类
 */
public class ResultBuildUtil {

    /**
     * @version 1.0
     * @author bhf
     * @date 2021/12/20 14:27
     * @Description: 返回成功，带数据
     */
    public static <T> RequestResult<T> success(T t){
        RequestResult<T> requestResult = new RequestResult<>();
        requestResult.setCode(CommonConstant.UNIFY_RETURN_SUCCESS_CODE);
        requestResult.setMsg(CommonConstant.UNIFY_RETURN_SUCCESS_MSG);
        requestResult.setData(t);
        return requestResult;
    }

    /**
     * @version 1.0
     * @author bhf
     * @date 2021/12/20 14:43
     * @Description: 返回成功，不带数据
     */
    public static <T> RequestResult<T> success(){
        return success(null);
    }

    /**
     * @version 1.0
     * @author bhf
     * @date 2021/12/20 14:44
     * @Description: 返回失败，带数据
     */
    public static <T> RequestResult<T> failed(T t){
        RequestResult<T> requestResult = new RequestResult<>();
        requestResult.setCode(CommonConstant.UNIFY_RETURN_FAILED_CODE);
        requestResult.setMsg(CommonConstant.UNIFY_RETURN_FAILED_MSG);
        requestResult.setData(t);
        return requestResult;
    }

    /**
     * @version 1.0
     * @author bhf
     * @date 2021/12/20 14:44
     * @Description: 返回失败，不带数据
     */
    public static <T> RequestResult<T> failed(){
        return failed(null);
    }

    /**
     * @version 1.0
     * @author bhf
     * @date 2021/12/20 14:44
     * @Description: 返回自定义失败，带数据
     */
    public static <T> RequestResult<T> cousfailed(String errCode,String errMsg){
        RequestResult<T> requestResult = new RequestResult<>();
        requestResult.setCode(errCode);
        requestResult.setMsg(errMsg);
        requestResult.setData(null);
        return requestResult;
    }

    /**
     * @version 1.0
     * @author bhf
     * @date 2021/12/20 14:44
     * @Description: 返回自定义失败，不带数据
     */
    public static <T> RequestResult<T> cousfailed(){
        return cousfailed(null,null);

    }

}
